<template>
	<view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				maxTryCount: 0
			}
		},
		onLoad(options) {
			this.maxTryCount = 10
			this.doRedirect(options)
		},
		methods: {
			doRedirect(options) {
			  this.maxTryCount -= 1
			  var plugin = requirePlugin("shop2cn-shopapis-plugin");
			  if (options.tar) {
			    const url = decodeURIComponent(options.tar)
			    const fullPath = plugin.getFullPath(url)
			    console.log('shopPlugin redirectTo:', fullPath)
			    if (!fullPath && this.maxTryCount > 0) {
			      setTimeout(() => {
			        console.log('doRedirect count ' + this.maxTryCount)
			        this.doRedirect(options)
			      }, 500);
			      return
			    }
			    wx.redirectTo({url: fullPath}) 
			  } else if (options.scene) {
			    plugin.parseRedirect(options).then((url) => {
			      if (!url && this.maxTryCount > 0) {
			        setTimeout(() => {
			          this.doRedirect(options)
			        }, 500);
			        return
			      }
			      uni.redirectTo({url: url})
			    })
			  }
			}
		}
	}
</script>

<style>
</style>
